package com.example.administrator.u17.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.u17.R;
import com.example.administrator.u17.activity.ZhangJieActivity;
import com.example.administrator.u17.model.ManHuaInfo;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2016/11/16.
 */

public class OtherBaseAdapter extends BaseAdapter {
    private Context context;
    private List<ManHuaInfo.Datas.Returns.Comicss> mData;

    public OtherBaseAdapter(Context context, List<ManHuaInfo.Datas.Returns.Comicss> mData) {
        this.context = context;
        this.mData = mData;
    }

    @Override
    public int getCount() {
        Log.e("TAG", "getCount: " + mData.size());
        return mData == null ? 0 : mData.size();
    }

    @Override
    public Object getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder vh;
        if (view == null) {
            view = View.inflate(context, R.layout.item_other, null);
            vh = new ViewHolder(view);
            view.setTag(vh);
        } else {
            vh = (ViewHolder) view.getTag();
        }
        Picasso.with(context).load(mData.get(i).cover).into(vh.iv);
        vh.tv.setText(mData.get(i).name);
        vh.iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, ZhangJieActivity.class);
                intent.putExtra("id", mData.get(i).comicId);
                intent.putExtra("count", mData.get(i).conTag);
                context.startActivity(intent);
            }
        });
        return view;
    }

    public static class ViewHolder {
        private ImageView iv;
        private TextView tv;

        public ViewHolder(View view) {
            iv = (ImageView) view.findViewById(R.id.iv_fragment_other);
            tv = (TextView) view.findViewById(R.id.tv_fragment_other);

        }

    }

}
